package mbp.tests;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeSet;

public class OfferState 
{
	
	public class ServiceInfo implements Comparable<ServiceInfo>
	{
		public Integer index;
		public Integer value;
		ServiceInfo(Integer index, Integer value)
		{
			this.index = index;
			this.value = value;
		}
		
		public int compareTo(ServiceInfo anotherServiceInfo)
		{
			final int BEFORE = -1;
		    final int EQUAL = 0;
		    final int AFTER = 1;
		    
		    if(this.value == anotherServiceInfo.value) return EQUAL;
		    
		    if(this.value < anotherServiceInfo.value) return BEFORE;
		    
		    if(this.value > anotherServiceInfo.value) return AFTER;
		    
		    return EQUAL;
		}
	}
	
	public String agentName;
	private List<ServiceInfo> offers;
	
	public OfferState(String agentName)
	{
		this.agentName = agentName;
		offers = new ArrayList<ServiceInfo>();
	}
	
	public void putService(Integer index, Integer utility)
	{
		offers.add(new ServiceInfo(index, utility));
	}
	
	public ArrayList getSortedList()
	{
		//HashMap<Integer, Integer> map = new LinkedHashMap<Integer, Integer>();
		//List<Integer> yourMapKeys = new ArrayList<Integer>(offers.keySet());
		//List<Integer> yourMapValues = new ArrayList<Integer>(offers.values());
		//for(int i = 0; i<yourMapKeys.size(); i++)
		//{
		//	System.out.println("key: " + yourMapKeys.get(i) + ", value: " + yourMapValues.get(i));
		//}
		//System.out.println("--");
		
		
		for(int i = 0; i<offers.size(); i++)
		{
			System.out.println("key: " + offers.get(i).index + ", value: " + offers.get(i).value);
		}
		System.out.println("--");
		
		Collections.sort(offers);
		
		for(int i = 0; i<offers.size(); i++)
		{
			System.out.println("key: " + offers.get(i).index + ", value: " + offers.get(i).value);
		}
		System.out.println("--");
		
		return (ArrayList) offers;
	}
	
	//public ArrayList getIndexes()
	//{
	//	List<Integer> indexes = new ArrayList<Integer>(getSortedList().keySet());
	//	return (ArrayList) indexes;
	//}
	
	//public ArraList getUtilities()
	//{
	//	
	//}

}
